<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: reviews.php 205 2013-09-22 07:59:23Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 205 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:59:23 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include ('includes/application_top.php');
$module_smarty = new Smarty;

require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');

require_once (DIR_FS_INC.'inc.word_count.php');
require_once (DIR_FS_INC.'inc.date_long.php');

$breadcrumb->add(NAVBAR_TITLE_REVIEWS, href_link(FILENAME_REVIEWS));
if ($_SESSION['customers_status']['customers_status_read_reviews'] == 0)
   redirect(href_link(FILENAME_LOGIN, '', 'SSL'));

require (DIR_WS_INCLUDES.'header.php');

if((isset($_GET['show_pid']) && (!empty($_GET['show_pid'])))) {
	$listing_query = "	SELECT 
								r.reviews_id,
								rd.reviews_text,
								r.reviews_rating,
								r.date_added,
								p.products_id,
								pd.products_name,
								p.products_image,
								r.customers_name
							FROM 
								".TABLE_REVIEWS." r,
								".TABLE_REVIEWS_DESCRIPTION." rd,
								".TABLE_PRODUCTS." p,
								".TABLE_PRODUCTS_DESCRIPTION." pd
							WHERE 
								p.products_status = '1'
							AND 
								p.products_id = '".(int)$_GET['show_pid']."'
							AND 
								rd.reviews_id = r.reviews_id
							AND 
								r.reviews_status = '1'
							AND 
								r.products_id = '".(int)$_GET['show_pid']."'
							AND 
								pd.products_id = '".(int)$_GET['show_pid']."'
							AND 
								pd.language_id = '".(int) $_SESSION['languages_id']."'
							AND 
								rd.languages_id = '".(int) $_SESSION['languages_id']."'
							ORDER BY 
								r.reviews_id DESC";

} else {
	$listing_query = "	SELECT 
								r.reviews_id,
								rd.reviews_text,
								r.reviews_rating,
								r.date_added,
								p.products_id,
								pd.products_name,
								p.products_image,
								r.customers_name
							FROM 
								".TABLE_REVIEWS." r,
								".TABLE_REVIEWS_DESCRIPTION." rd,
								".TABLE_PRODUCTS." p,
								".TABLE_PRODUCTS_DESCRIPTION." pd
							WHERE 
								p.products_status = '1'
							AND 
								p.products_id = r.products_id
							AND 
								r.reviews_id = rd.reviews_id
							AND 
								r.reviews_status = '1'
							AND 
								p.products_id = pd.products_id
							AND 
								pd.language_id = '".(int) $_SESSION['languages_id']."'
							AND 
								rd.languages_id = '".(int) $_SESSION['languages_id']."'
							ORDER BY 
								r.reviews_id DESC";
}

$listing = new page_break($listing_query, $_GET['page'], true, 'reviews.php');

if($listing->result) {
	
	include(DIR_WS_MODULES.'page_per_site.php');
	
	$module_data = array ();
	while(!$listing->sql_string->EOF) {
		
		if($listing->sql_string->fields['products_image']!='')
			$product_img = DIR_WS_THUMBNAIL_IMAGES.$listing->sql_string->fields['products_image'];
		else
			$product_img = DIR_WS_IMAGES.'no_img_thumbnail.jpg';
			
		$count = word_count($listing->sql_string->fields['reviews_text']);
		if($count > 320) {
			if(MODULE_SEO_URL_INDEX_STATUS == 'True')
				$link = 'review-'.$listing->sql_string->fields['reviews_id'].'/'.get_url_friendly_text(get_products_name($listing->sql_string->fields['products_id'])).'.html';
			else
				$link = href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'reviews_id='.$listing->sql_string->fields['reviews_id']);
				
			$text = substr($listing->sql_string->fields['reviews_text'], 0, 320).' ...[<a href="'.$link.'">mehr lesen</a>]';
		} else
			$text = $listing->sql_string->fields['reviews_text'];
		
		$module_data[] = array ('PRODUCTS_IMAGE' => $product_img,
								'PRODUCTS_LINK' => href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id='.$listing->sql_string->fields['products_id'].'&reviews_id='.$listing->sql_string->fields['reviews_id']),
								'PRODUCTS_NAME' => $listing->sql_string->fields['products_name'],
								'AUTHOR' => $listing->sql_string->fields['customers_name'],
								'TEXT_COUNT' => sprintf(TEXT_REVIEW_WORD_COUNT, $count),
								'TEXT' => $text,
								'RATING' => image('templates/'.CURRENT_TEMPLATE.'/img/stars_'.$listing->sql_string->fields['reviews_rating'].'.png', sprintf(TEXT_OF_5_STARS, $listing->sql_string->fields['reviews_rating'])));
								
		$listing->sql_string->MoveNext();
	}
	$module_smarty->assign('module_content', $module_data);
	$module_smarty->assign('NAVIGATION', $navigation);
	$module_smarty->assign('BUTTON_BACK', '<a href="javascript:history.back(-1)">'.image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>');
	$module_smarty->assign('language', $_SESSION['language']);
	
} else
	$module_smarty->assign('NAVIGATION', 'Es gibt derzeit noch keine Bewertungen');
	
$module_smarty->assign('language', $_SESSION['language']);
if(!CacheCheck()) {
	$module_smarty->caching = false;
	$content = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/reviews.html');
} else {
	$module_smarty->caching = true;
	$module_smarty->cache_lifetime = CACHE_LIFETIME;
	$module_smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = $_SESSION['language'].'_'.$_GET['show_pid'];
	$content = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/reviews.html', $cache_id);
}

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $content);
$smarty->caching = false;
if(!defined('RM'))
	$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');

include ('includes/application_bottom.php');
?>